import { Yanim } from "@/components/y-anim/script/yanim";
import { useUser } from "@/stores/user";
import { ref } from "vue";

const user = useUser();
const pages = ref(0);
const idx = ref(1);
const filterList = ref<Record[]>([]);
async function getData() {
    const obj = await user.getEnergyFlowNew(10, idx.value) as RootObject;
    if (obj !== null) {
        console.log('yzt能量列表', obj);
        for (let i = 0; i < obj.records.length; i++) {
            if (obj.records[i].action === 'REGISTER_COMPLETE') {
                Yanim.energy = obj.records[i].amount;
            }
        }
        pages.value = obj.pages;
        filterList.value = obj.records;
    } else {
        filterList.value = [];
    }
}


export { user, filterList, getData, idx, pages };
export type { Record };


interface RootObject {
    records: Record[];
    total: number;
    size: number;
    current: number;
    orders: any[];
    optimizeCountSql: boolean;
    searchCount: boolean;
    pages: number;
}

interface Record {
    id: number;
    action: string;
    type: number;
    createTime: number;
    amount: number;
    days: number;
    channelId?: number;
    channelName?: string;
}